﻿using System;
using System.Web;
using System.Collections.Generic;
using System.Diagnostics;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Collections.ObjectModel;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using System.Collections.Specialized;
using BdcAdmin = Microsoft.SharePoint.BusinessData.Administration;

using Microsoft.BusinessData;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.BusinessData.Administration;
using Microsoft.SharePoint.BusinessData.SharedService;
using Microsoft.SharePoint.BusinessData.MetadataModel;

namespace EntiyInstanceSiteLib
{
    public partial class SharepointForm : Form
    {

        public string sharepointURL= @"http://" + System.Environment.MachineName.ToLower() + @"/";
        
        public SharepointForm()
        {
            InitializeComponent();
            sharePointURLComboBox.AutoCompleteMode = AutoCompleteMode.Suggest;
            sharePointURLComboBox.AutoCompleteSource = AutoCompleteSource.ListItems;
        }
        
        
        private void nextButton1_Click(object sender, EventArgs e)
        {

            sharepointURL = sharePointURLComboBox.Text.ToString();
            if (ValidateURL())
                this.Close();              

        }

        private void SharepointForm_Load(object sender, EventArgs e)
        {
            sharePointURLComboBox.Items.Add(sharepointURL);
            sharePointURLComboBox.SelectedIndex = 0;            
        }

        // validate the URl is well formed or not 
        // appends the "/" char, if url does not end with "/"
        private bool ValidateURL()
        {
            if (!Uri.IsWellFormedUriString(sharepointURL, UriKind.Absolute))
            {
                MessageBox.Show("URL is not well-formed");
                return false;
            }
            if (!sharepointURL.EndsWith("/"))
            {
                sharepointURL += "/";
            }
            return true;
        }
        

       

     


 }
}
